// 
export const getDayBegin = (diff=0) => {
    let date = new Date().getTime() - diff * 24 * 60 * 60 * 1000;
    date = new Date(date);
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    date.setMilliseconds(0);
    return date;
}

export const getDayEnd = (diff=0) => {
    let date = new Date().getTime() - diff * 24 * 60 * 60 * 1000;
    date = new Date(date);
    date.setHours(23);
    date.setMinutes(59);
    date.setSeconds(59);
    date.setMilliseconds(999);
    return date;
}
// formatNumber
export const formatNumber = (n) => {
    n = n.toString()
    return n[1] ? n : '0' + n
}
// 获取上月开始日期
export const getMonthStartDay = (diff) => {
    let date = new Date();
    date.setMonth(date.getMonth() - diff);
    date.setDate(1);
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    date.setMilliseconds(0);
    return date;
}
// 获取上月结束日期
export const getMonthEndDay = (diff) => {
    let date = new Date();
    date.setMonth(date.getMonth() - diff);
    date.setMonth(date.getMonth() + 1);
    date.setDate(0);
    date.setHours(23);
    date.setMinutes(59);
    date.setSeconds(59);
    date.setMilliseconds(999);
    return date;
}
// 将时间转化为yyyy-MM-dd HH:mm:ss
export const formatDate = (date) => {
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    let hour = date.getHours();
    let minute = date.getMinutes();
    let second = date.getSeconds();
    return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':');
}